package br.com.jk.financeiro.contaBanco;

import br.com.jk.empresa.Empresa;
import br.com.jk.financeiro.banco.Banco;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author camilo
 */
@Entity
@Table(name = ContaBancoDao.NAME_TABLE, schema = ContaBancoDao.NAME_SCHEMA, uniqueConstraints = {
  @UniqueConstraint(name = ContaBancoDao.NAME_UK_CONTA_AGENCIA, columnNames = {
    ContaBancoDao.NAME_COLUMN_BANCO,
    ContaBancoDao.NAME_COLUMN_AGENCIA,
    ContaBancoDao.NAME_COLUMN_CONTA})})
public class ContaBanco implements Serializable {

  public static final String ATTRIBUTE_ID = "id";
  public static final String ATTRIBUTE_AGENCIA = "agencia";
  public static final String ATTRIBUTE_CONTA = "conta";
  public static final String ATTRIBUTE_EMPRESA = "empresa";
  public static final String ATTRIBUTE_DESCRICAO = "descricao";
  public static final String ATTRIBUTE_BANCO = "banco";
  @Id
  @SequenceGenerator(name = ContaBancoDao.NAME_SEQUENCE, sequenceName = ContaBancoDao.NAME_SEQUENCE,
          schema = ContaBancoDao.NAME_SCHEMA)
  @GeneratedValue(strategy = GenerationType.AUTO, generator = ContaBancoDao.NAME_SEQUENCE)
  private int id;
  @Column(name = ContaBancoDao.NAME_COLUMN_AGENCIA)
  private String agencia;
  @Column(name = ContaBancoDao.NAME_COLUMN_CONTA)
  private String conta;
  @Column(nullable = false, name = ContaBancoDao.NAME_COLUMN_DESCRICAO)
  private String descricao;
  @ManyToOne
  @JoinColumn(name = ContaBancoDao.NAME_COLUMN_EMPRESA, nullable = false, foreignKey = @ForeignKey(name = ContaBancoDao.NAME_FK_EMPRESA))
  private Empresa empresa;
  @ManyToOne
  @JoinColumn(name = ContaBancoDao.NAME_COLUMN_BANCO, nullable = false, foreignKey = @ForeignKey(name = ContaBancoDao.NAME_FK_BANCO))
  private Banco banco;

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 97 * hash + this.id;
    hash = 97 * hash + Objects.hashCode(this.agencia);
    hash = 97 * hash + Objects.hashCode(this.conta);
    hash = 97 * hash + Objects.hashCode(this.descricao);
    hash = 97 * hash + Objects.hashCode(this.empresa);
    hash = 97 * hash + Objects.hashCode(this.banco);
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final ContaBanco other = (ContaBanco) obj;
    if (this.id != other.id) {
      return false;
    }
    if (!Objects.equals(this.agencia, other.agencia)) {
      return false;
    }
    if (!Objects.equals(this.conta, other.conta)) {
      return false;
    }
    if (!Objects.equals(this.descricao, other.descricao)) {
      return false;
    }
    if (!Objects.equals(this.empresa, other.empresa)) {
      return false;
    }
    return Objects.equals(this.banco, other.banco);
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getAgencia() {
    return agencia;
  }

  public void setAgencia(String agencia) {
    this.agencia = agencia;
  }

  public String getConta() {
    return conta;
  }

  public void setConta(String conta) {
    this.conta = conta;
  }

  public String getDescricao() {
    return descricao;
  }

  public void setDescricao(String descricao) {
    this.descricao = descricao;
  }

  public Empresa getEmpresa() {
    return empresa;
  }

  public void setEmpresa(Empresa empresa) {
    this.empresa = empresa;
  }

  public Banco getBanco() {
    return banco;
  }

  public void setBanco(Banco banco) {
    this.banco = banco;
  }
}
